<template>
	<view>
		<view class="move_nav" v-for="(item,index) in dataList" :key="index">
			<image :src="item.img">
			</image>
			<view class="nav">
				<view class="text">
					<view class="name">{{item.movie_name}}</view>
					<view class="title">{{item.year}}/{{item.district}}</view>
					<view class="title">{{item.actor.length>0?item.actor.join(","):"未知"}}</view>
					<view class="title">{{item.active_about}}</view>
				</view>
				<view class="play" @click="toPlay(item._id)">
					<view class="play_nav">立即播放</view>
				</view>
			</view>
		</view>
		<view style="display: flex;justify-content: center;width: 100%;">
			<uni-load-more :status="status"></uni-load-more>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				key: "",
				dataList: "",
				search:"",
				page:1,
				size:10,
				status:'more'
			}
		},
		methods: {
			// 获取相对应的数据
			async getDataList() {
				this.getList()
			},
			toPlay(id){
				uni.navigateTo({
					url:`../detail/detail?id=${id}`
				})
			},
			// 搜索更多
		async getList(){
				if (this.key == "最新电影") {
					let res = await uniCloud.callFunction({
						name: "new_active"
					})
					console.log(res);
					this.dataList=this.page==1?res.result.data:[...this.dataList,...res.result.data]
					if(res.result.data.length==this.size){
						this.status="more"
					}else{
						this.status="noMore"
					}
				}
				if(this.key == "动漫电影"){
					let res = await uniCloud.callFunction({
						name: "TypeList",
						data:{
							type:"动漫"
						}
					})
					this.dataList=this.page==1?res.result.data:[...this.dataList,...res.result.data]
					if(res.result.data.length==this.size){
						this.status="more"
					}else{
						this.status="noMore"
					}
				}
				if(this.search){
					let res=await uniCloud.callFunction({
						name:"search_list",
						data:{
							page:this.page,
							size:this.size,
							key:this.search
						}
					})
					this.dataList=this.page==1?res.result.data:[...this.dataList,...res.result.data]
					if(res.result.data.length==this.size){
						this.status="more"
					}else{
						this.status="noMore"
					}
				}
			}

		},
		onLoad(option) {
			if(option.key){
				this.key = option.key
			}
			if(option.search){
				this.search=option.search
			}
			
			this.getDataList()
		},
		onReachBottom(){
			if(this.status=="more"){
				this.status=="loading"
				this.page+=1
				this.getList()
			}
		}
	}
</script>

<style scoped>
	.move_nav {
		display: flex;
		background-color: #f1f3f5;
		padding: 25rpx;
		margin: 20rpx;
		border-radius: 20rpx;

	}

	.move_nav image {
		width: 200rpx;
		height: 260rpx;
		margin-right: 30rpx;
	}

	.name {
		font-weight: 600;
	}

	.title {
		font-size: 25rpx;
		color: rgba(0, 0, 0, 0.5);
		line-height: 50rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.play {
		display: flex;
		justify-content:flex-end;
	}

	.nav {
		flex: 1;
	}
	.play_nav{
		background-color: #ffd43b;
		padding: 10rpx 30rpx;
		border-radius: 10rpx;
	}
	.text{
		width: 400rpx;
	}
</style>
